import { defineAxiosExpandConfig } from '@/utils/request'
import { Spin, message } from 'antd'
import ReactDOM from 'react-dom/client'
import { Provider } from 'react-redux'
import { RouterProvider } from 'react-router-dom'
import { YmConfigProvider } from 'ym-design'
import { store } from './redux/store'
import { router } from './routes/routerConfig'
import './styles/index.less'

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)

defineAxiosExpandConfig({
  getHeaders() {
    return {
      ClientType: 'WebEnt',
      baseEntId: '', //store.getState().loginEnt.entId,
      baseuserid: '', //store.getState().loginToken,
      AuthToken: '' //store.getState().loginAuthToken
    }
  },
  messageHandler(msg, errCode) {
    message.destroy()
    message.error(msg)
    if (['5002', '1006', 'PR002', '1008'].includes(errCode)) {
      console.error('接口请求，errCode：', errCode)
    }
  }
})

root.render(
  <YmConfigProvider
    theme={{
      token: {
        colorPrimary: '#F66E2C',
        borderRadius: 2
      }
    }}
  >
    {/* <App> */}
    <Provider store={store}>
      <RouterProvider router={router} fallbackElement={<Spin />} />
    </Provider>
    {/* </App> */}
  </YmConfigProvider>
)
